// pages/guest_message/guest_message.js
var app = getApp();
var url = app.globalData.url;
var headers,initX,moveX,dom;
Page({
  data:{
    url:"https://app1.sztravel.com.cn/file/weixinapp/img",
    info:[],
    actIdx:null
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  onReady:function(){
    // 页面渲染完成
  },
  changeMes:function(e){
   var touristid=e.currentTarget.dataset.touristid;
    wx.navigateTo({
      url: '../add_tourist/add_tourist?touristid='+touristid+'',
    })
  },
  del:function(e){ 
    var peerid = e.currentTarget.dataset.id;
    wx.request({
      url: url +'api/delete_one_peer',
      method:'POST',
      header:headers,
      data:{
        "peer_id": peerid
      },
      success:function(data){
        console.log(data)
        
        wx.showModal({
          title: '来自伴行的提示',
          content: data.data.message,
          showCancel:false,
          success:function(){
            if(data.data.result==1){
              wx.redirectTo({
                url: 'guest_message',
              })
            }
          }
        })
      }
    })
  },
  touchMove:function(e){
    var that=this
    // console.log(e.touches[0].clientX) 
    if (e.currentTarget.dataset.idx==dom){//同一列
      moveX = e.touches[0].clientX;
      // console.log(moveX-initX)
      if(moveX-initX<=0){//左滑展开
        if (moveX - initX <= -60) {
          console.log("ok")
          that.setData({
            actIdx: dom
          })
          // console.log(that.data)
          
        } 
      } else if (moveX - initX >=20){
        that.setData({
          actIdx: null
        })
      }
    }
  },
  touchStart:function(e){
      console.log(e)
      dom = e.currentTarget.dataset.idx;
      initX=e.touches[0].clientX;
      console.log(initX)
  },
  onShow:function(){
    // 页面显示
    var that=this;
    headers = app.globalData.headers;
    wx.request({
      url: url+'api/get_my_peer_list',
      header:headers,
      success:function(data){
        console.log(data)
        if(data.data.result===1){
          that.setData({
            info:data.data.data.peer_list
          })
        }else{
          wx.showModal({
            title: '来自伴行的提示',
            content:data.data.message,
            showCancel:false
          })
        }
        console.log(that.data)
      }
    })
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})